#pragma once

#include "Protocol.hpp"
#include <iostream>

class Cal
{
public:
    // 服务逻辑处理
    Response Execute(Request &req)
    {
        Response res(0, 0);
        switch (req.GetOper())
        {
        case '+':
            res.SetResult(req.GetX() + req.GetY());
            break;
        case '/':
            if (req.GetY() == 0)
                res.SetCode(1); // 除数错误
            else
                res.SetResult(req.GetX() / req.GetY());
            break;
        case '*':
            res.SetResult(req.GetX() * req.GetY());
            break;
        case '-':
            res.SetResult(req.GetX() - req.GetY());
            break;
        case '%':
            if(req.GetY()==0) res.SetCode(2);
            else res.SetResult(req.GetX()%req.GetY());
            break;
        default:
            res.SetCode(3); // 非法操作
            break;
        }
        return res;
    }
};